package com.hsc.yalebao.weight;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.os.Looper;
import android.os.Parcelable;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.animation.AccelerateDecelerateInterpolator;
import com.hsc.pcddfivepcdd.R.styleable;

@TargetApi(11)
public class SlideSwitch extends View
{
  private static final int DEFAULT_COLOR_THEME = 0;
  private static final int RIM_SIZE = 6;
  public static final int SHAPE_CIRCLE = 2;
  public static final int SHAPE_RECT = 1;
  private int alpha;
  private RectF backCircleRect;
  private Rect backRect;
  private int color_theme;
  private int diffX = 0;
  private int eventLastX;
  private int eventStartX;
  private RectF frontCircleRect;
  private Rect frontRect;
  private int frontRect_left;
  private int frontRect_left_begin = 6;
  private boolean isOpen;
  private SlideListener listener = null;
  private int max_left;
  private int min_left;
  private Paint paint = new Paint();
  private int shape;
  private boolean slideable = true;

  public SlideSwitch(Context paramContext)
  {
    this(paramContext, null);
  }

  public SlideSwitch(Context paramContext, AttributeSet paramAttributeSet)
  {
    this(paramContext, paramAttributeSet, 0);
  }

  public SlideSwitch(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    this.paint.setAntiAlias(true);
    TypedArray localTypedArray = paramContext.obtainStyledAttributes(paramAttributeSet, R.styleable.slideswitch);
    this.color_theme = localTypedArray.getColor(0, DEFAULT_COLOR_THEME);
    this.isOpen = localTypedArray.getBoolean(1, false);
    this.shape = localTypedArray.getInt(2, 1);
    localTypedArray.recycle();
  }

  private void invalidateView()
  {
    if (Looper.getMainLooper() == Looper.myLooper())
    {
      invalidate();
      return;
    }
    postInvalidate();
  }

  public void initDrawingVal()
  {
    int i = getMeasuredWidth();
    int j = getMeasuredHeight();
    this.backCircleRect = new RectF();
    this.frontCircleRect = new RectF();
    this.frontRect = new Rect();
    this.backRect = new Rect(0, 0, i, j);
    this.min_left = 6;
    if (this.shape == 1)
    {
      this.max_left = (i / 2);
      if (!this.isOpen)
        break label126;
      this.frontRect_left = this.max_left;
    }
    for (this.alpha = 255; ; this.alpha = 0)
    {
      this.frontRect_left_begin = this.frontRect_left;
      return;
      this.max_left = (-6 + (i - (j - 12)));
      break;
      label126: this.frontRect_left = 6;
    }
  }

  public int measureDimension(int paramInt1, int paramInt2)
  {
    int i = View.MeasureSpec.getMode(paramInt2);
    int j = View.MeasureSpec.getSize(paramInt2);
    int k;
    if (i == 1073741824)
      k = j;
    do
    {
      return k;
      k = paramInt1;
    }
    while (i != -2147483648);
    return Math.min(k, j);
  }

  public void moveToDest(final boolean paramBoolean)
  {
    int[] arrayOfInt = new int[2];
    arrayOfInt[0] = this.frontRect_left;
    if (paramBoolean);
    for (int i = this.max_left; ; i = this.min_left)
    {
      arrayOfInt[1] = i;
      ValueAnimator localValueAnimator = ValueAnimator.ofInt(arrayOfInt);
      localValueAnimator.setDuration(500L);
      localValueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
      localValueAnimator.start();
      localValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
      {
        public void onAnimationUpdate(ValueAnimator paramAnonymousValueAnimator)
        {
          SlideSwitch.this.frontRect_left = ((Integer)paramAnonymousValueAnimator.getAnimatedValue()).intValue();
          SlideSwitch.this.alpha = ((int)(255.0F * SlideSwitch.this.frontRect_left / SlideSwitch.this.max_left));
          SlideSwitch.this.invalidateView();
        }
      });
      localValueAnimator.addListener(new AnimatorListenerAdapter()
      {
        public void onAnimationEnd(Animator paramAnonymousAnimator)
        {
          if (paramBoolean)
          {
            SlideSwitch.this.isOpen = true;
            if (SlideSwitch.this.listener != null)
              SlideSwitch.this.listener.open();
            SlideSwitch.this.frontRect_left_begin = SlideSwitch.this.max_left;
            return;
          }
          SlideSwitch.this.isOpen = false;
          if (SlideSwitch.this.listener != null)
            SlideSwitch.this.listener.close();
          SlideSwitch.this.frontRect_left_begin = SlideSwitch.this.min_left;
        }
      });
      return;
    }
  }

  protected void onDraw(Canvas paramCanvas)
  {
    if (this.shape == 1)
    {
      this.paint.setColor(-7829368);
      paramCanvas.drawRect(this.backRect, this.paint);
      this.paint.setColor(this.color_theme);
      this.paint.setAlpha(this.alpha);
      paramCanvas.drawRect(this.backRect, this.paint);
      this.frontRect.set(this.frontRect_left, 6, -6 + (this.frontRect_left + getMeasuredWidth() / 2), -6 + getMeasuredHeight());
      this.paint.setColor(-1);
      paramCanvas.drawRect(this.frontRect, this.paint);
      return;
    }
    int i = -6 + this.backRect.height() / 2;
    this.paint.setColor(-7829368);
    this.backCircleRect.set(this.backRect);
    paramCanvas.drawRoundRect(this.backCircleRect, i, i, this.paint);
    this.paint.setColor(this.color_theme);
    this.paint.setAlpha(this.alpha);
    paramCanvas.drawRoundRect(this.backCircleRect, i, i, this.paint);
    this.frontRect.set(this.frontRect_left, 6, -12 + (this.frontRect_left + this.backRect.height()), -6 + this.backRect.height());
    this.frontCircleRect.set(this.frontRect);
    this.paint.setColor(-1);
    paramCanvas.drawRoundRect(this.frontCircleRect, i, i, this.paint);
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    super.onMeasure(paramInt1, paramInt2);
    int i = measureDimension(280, paramInt1);
    int j = measureDimension(140, paramInt2);
    if ((this.shape == 2) && (i < j))
      i = j * 2;
    setMeasuredDimension(i, j);
    initDrawingVal();
  }

  protected void onRestoreInstanceState(Parcelable paramParcelable)
  {
    if ((paramParcelable instanceof Bundle))
    {
      Bundle localBundle = (Bundle)paramParcelable;
      this.isOpen = localBundle.getBoolean("isOpen");
      paramParcelable = localBundle.getParcelable("instanceState");
    }
    super.onRestoreInstanceState(paramParcelable);
  }

  protected Parcelable onSaveInstanceState()
  {
    Bundle localBundle = new Bundle();
    localBundle.putParcelable("instanceState", super.onSaveInstanceState());
    localBundle.putBoolean("isOpen", this.isOpen);
    return localBundle;
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    boolean bool1 = true;
    if (!this.slideable)
      bool1 = super.onTouchEvent(paramMotionEvent);
    int j;
    do
    {
      return bool1;
      switch (MotionEventCompat.getActionMasked(paramMotionEvent))
      {
      default:
        return bool1;
      case 0:
        this.eventStartX = ((int)paramMotionEvent.getRawX());
        return bool1;
      case 2:
        this.eventLastX = ((int)paramMotionEvent.getRawX());
        this.diffX = (this.eventLastX - this.eventStartX);
        j = this.diffX + this.frontRect_left_begin;
        if (j > this.max_left)
          j = this.max_left;
        if (j < this.min_left)
          j = this.min_left;
        break;
      case 1:
      }
    }
    while ((j < this.min_left) || (j > this.max_left));
    this.frontRect_left = j;
    this.alpha = ((int)(255.0F * j / this.max_left));
    invalidateView();
    return bool1;
    int i = (int)(paramMotionEvent.getRawX() - this.eventStartX);
    this.frontRect_left_begin = this.frontRect_left;
    if (this.frontRect_left_begin > this.max_left / 2)
    {
      bool2 = bool1;
      if (Math.abs(i) < 3)
        if (!bool2)
          break label238;
    }
    label238: for (boolean bool2 = false; ; bool2 = bool1)
    {
      moveToDest(bool2);
      return bool1;
      bool2 = false;
      break;
    }
  }

  public void setShapeType(int paramInt)
  {
    this.shape = paramInt;
  }

  public void setSlideListener(SlideListener paramSlideListener)
  {
    this.listener = paramSlideListener;
  }

  public void setSlideable(boolean paramBoolean)
  {
    this.slideable = paramBoolean;
  }

  public void setState(boolean paramBoolean)
  {
    this.isOpen = paramBoolean;
    initDrawingVal();
    invalidateView();
    if (this.listener != null)
    {
      if (paramBoolean)
        this.listener.open();
    }
    else
      return;
    this.listener.close();
  }

  public static abstract interface SlideListener
  {
    public abstract void close();

    public abstract void open();
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.weight.SlideSwitch
 * JD-Core Version:    0.6.2
 */